import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

public class cxc3 {

    public static void main(String[] args) {
        List<String> equations = generateEquations(50);  // 这里可以调整生成的算式数量，此处示例为20个
        printEquations(equations);
    }

    // 生成指定数量的算式
    public static List<String> generateEquations(int numEquations) {
        List<String> equations = new ArrayList<>();
        Set<String> generatedSet = new HashSet<>();  // 用于记录已经生成过的算式，避免重复
        Random random = new Random();
        while (equations.size() < numEquations) {
            boolean isAddition = random.nextBoolean();
            String equation;
            if (isAddition) {
                equation = generateAddition();
            } else {
                equation = generateSubtraction();
            }
            if (!generatedSet.contains(equation)) {
                generatedSet.add(equation);
                equations.add(equation);
            }
        }
        return equations;
    }

    // 生成加法算式，保证和不超过100
    public static String generateAddition() {
        Random random = new Random();
        int num1 = random.nextInt(101) + 100;  // 生成100到200之间的数
        int num2 = random.nextInt(201) - 100;  // 生成 -100到100之间的数
        int sum = num1 + num2;
        while (sum > 100) {
            num2 = random.nextInt(201) - 100;
            sum = num1 + num2;
        }
        return num1 + " + " + num2 + " = " + sum;
    }

    // 生成减法算式，保证差不小于0
    public static String generateSubtraction() {
        Random random = new Random();
        int num1 = random.nextInt(101) + 100;  // 生成100到200之间的数
        int num2 = random.nextInt(101);  // 生成0到100之间的数
        int diff = num1 - num2;
        return num1 + " - " + num2 + " = " + diff;
    }

    // 格式化输出算式列表
    public static void printEquations(List<String> equations) {
        int equationsPerLine = 4;  // 可以根据需要调整每行显示的算式数量
        for (int i = 0; i < equations.size(); i++) {
            System.out.print(equations.get(i));
            if ((i + 1) % equationsPerLine == 0) {
                System.out.println();
            } else {
                System.out.print("\t");
            }
        }
    }
}
